<?php

require_once 'AbstractService.php';
require_once __DIR__ . "/../lib/MailTemplate.php";

/**
 * 发送
 * Class SendMailService
 * time 2020/11/11 12:24
 * author zrone <xujining415@gmail.com>
 * copyright zrone <xujining415@gmail.com>
 */
class SendMailService extends AbstractService
{
    public function __invoke($data)
    {
        $logicParams = $this->getLogicParams($data['key'], $data['subject'], $data['params']);

        $result = $this->terminal($logicParams, 'SingleSendMail');

        if (isset($result["EnvId"])) {
            return "发送成功";
        } else {
            return "请求失败，请刷新重试!";
        }
    }

    private function getLogicParams($type, $subject, $params)
    {
        $html = "";
        switch ($type) {
            case "7Bhk03":
                $html = str_replace(["@var(tradeno)"], ["订单号"], MailTemplate::TEMPLATE[$type]);
                break;
            case "DQaRn1":
                $html = str_replace(["@var(service)", "@var(m400)"], ["服务名称", "400电话"], MailTemplate::TEMPLATE[$type]);
                break;
            case "UcA394":
                $html = str_replace(["@var(user)", "@var(payer)", "@var(service)", "@var(timer)", "@var(m400)"], ["用户名", "买家名字", "服务名字", "时间", "400电话"], MailTemplate::TEMPLATE[$type]);
                break;
            case "oRdxu1":
                $html = str_replace(["@var(service)", "@var(m400)"], ["服务名称", "400电话"], MailTemplate::TEMPLATE[$type]);
                break;
            case "As8zF2":
                $html = str_replace(["@var(tradeno)"], ["订单号"], MailTemplate::TEMPLATE[$type]);
                break;
            case "eFtJ03":
                $html = MailTemplate::TEMPLATE[$type];
                break;
            case "ngjm6":
                $html = str_replace(["@var(code)"], ["验证码1234"], MailTemplate::TEMPLATE[$type]);
                break;
            case "QSGP61":
                $html = str_replace(["@var(code)"], ["验证码1234"], MailTemplate::TEMPLATE[$type]);
                break;
            case "OJsW4":
                $html = str_replace(["@var(code)"], ["注册验证码1234"], MailTemplate::TEMPLATE[$type]);
                break;
            case "Mt3Q12":
                $html = str_replace(["@var(code)"], ["修改验证码1234"], MailTemplate::TEMPLATE[$type]);
                break;
            case "egWpT2":
                $html = str_replace(["@var(code)"], ["修改验证码1234"], MailTemplate::TEMPLATE[$type]);
                break;
            case "0ZY4H2":
                $html = str_replace(["@var(tradeno)", "var://@link(url)"], ["发票订单号", "http://www.baidu.com"], MailTemplate::TEMPLATE[$type]);
                break;
        }

        return [
            "AccountName" => "info@come-i.com",
            "AddressType" => 1,
            "ReplyToAddress" => "false",
            "Subject" => $subject,
            "ToAddress" => "xujining2008@126.com",
            "ClickTrace" => 0,
            "FromAlias" => "共脉网<come-i.com>",
            "HtmlBody" => $html
        ];


    }
}